package com.yc.spring.test3;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import com.yc.spring.test2.Autowired2;

public class Stt3 {
	
	public void m1() throws NoSuchFieldException, SecurityException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		St32 st = new St32();
		Class<? extends St32> Cst = st.getClass();
		Field[] declaredFields = Cst.getDeclaredFields();
		for (Field field : declaredFields) {
			Autowired2 ann = field.getAnnotation(Autowired2.class);
			if (null != ann) {
				String methodName = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
				Method method = Cst.getMethod(methodName, St31.class);
				method.invoke(st, new St31());
			}
			
		}
		st.m2();
		
		
	}
	
	public static void main(String[] args) {
		Stt3 st = new Stt3();
		try {
			st.m1();
		} catch (NoSuchFieldException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
